package xyf.p01.array_nodelist;

import commons.ListNode;

/**
 * ClassName: J022_KNode
 * Description:
 * Author: xyf
 * Date: 9/7/22 7:43 PM
 * Version: 1.0
 **/
public class J022_KNode
{
    public ListNode getKthFromEnd(ListNode head, int k)
    {
        int size = 0;
        ListNode tmp = head;
        while (tmp != null)
        {
            tmp = tmp.next;
            size++;
        }

        int number = size - k;

        while (number > 0)
        {
            head = head.next;
            number--;
        }
        return head;
    }
}
